<?php

use yii\db\Migration;

/**
 * Handles the creation of table `{{%ticket_sales}}`.
 * Has foreign keys to the tables:
 *
 * - `{{%event}}`
 */
class m240419_125120_create_ticket_sales_table extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $this->createTable('{{%ticket_sales}}', [
            'id' => $this->primaryKey(),
            'event_id' => $this->integer()->notNull(),
            'date_sale' => $this->datetime(),
            'is_cancell' => $this->boolean(),
            'is_refund' => $this->boolean(),
            'tariff' => $this->money(),
            'selling_platform' => $this->string(),
            'payment_method' => $this->string(),
        ]);

        // creates index for column `event_id`
        $this->createIndex(
            '{{%idx-ticket_sales-event_id}}',
            '{{%ticket_sales}}',
            'event_id'
        );

        // add foreign key for table `{{%event}}`
        $this->addForeignKey(
            '{{%fk-ticket_sales-event_id}}',
            '{{%ticket_sales}}',
            'event_id',
            '{{%event}}',
            'id',
            'CASCADE'
        );
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        // drops foreign key for table `{{%event}}`
        $this->dropForeignKey(
            '{{%fk-ticket_sales-event_id}}',
            '{{%ticket_sales}}'
        );

        // drops index for column `event_id`
        $this->dropIndex(
            '{{%idx-ticket_sales-event_id}}',
            '{{%ticket_sales}}'
        );

        $this->dropTable('{{%ticket_sales}}');
    }
}
